#ifndef IMAGESCROLLER_H
#define IMAGESCROLLER_H

#include <QtGui>
#include <QApplication>
#include "BasicConfig.h"
#include "GhostFunction.h"
#include "imagestructure.h"
#include "imagestructure.h"
#include <QHttp>
#include <QThread>


extern inline QString  KMega( int peso  )
{
    QString humanread;
    qreal  faktor = 1024.00;

    qreal bytesizefile = peso / faktor;
    int kilo = 0;
    
    if (bytesizefile > 0) {
        if (bytesizefile < 1) {
           kilo = 1; 
        } else {
           kilo = bytesizefile;
        }
    }
    
   if (kilo < 1025) {
   humanread = QString("Kb.%1").arg(kilo);
   return humanread;
   }
   
   qreal megad = bytesizefile / faktor;
   
   if (megad < 1025) {
   humanread = QString("MB.%1").arg(megad, 0, 'f', 2);
   return humanread;
   } else {
            qreal gigab = megad / faktor;
            humanread = QString("GB.%1").arg(gigab, 0, 'f', 2);
       
       
   }
   
return humanread;
}




class LoadGetImage : public QHttp
{
    Q_OBJECT
//
public: 
     LoadGetImage( int nr , QUrl url_send );
     void Start();
     inline int Get_id() { return cid; }
     inline int Htpp_id() { return Http_id; } 
     inline QPixmap pics() { return resultimage; } 
     int cid;
     int Http_id;
    QHttpRequestHeader header;
    QUrl url;
    QPixmap resultimage;
    signals:
      void take(int);
    public slots:
     void ImageReady( bool error );
};



class Gloader : public QThread
{
    Q_OBJECT
     
public:
  void Setting( QObject *parent , int id , QUrl url_send ); 
protected:
  void run();
  signals:
private:
    int cid;
    QUrl url;
    LoadGetImage *Rhttp;
    QObject* receiver;
}; 







//
class ImageScroller : public QListWidget
{
     Q_OBJECT
//
public:
ImageScroller( QWidget* = 0 );
inline QPixmap cur() { return current; }
QPixmap current;
QString streamSave();
void importStream( const QString inside );
int  kilosize();
protected:
  void TestLoad();
  void dropEvent ( QDropEvent * e );
  void dragEnterEvent( QDragEnterEvent * e );
  void dragMoveEvent ( QDragMoveEvent * e );
  void AppendImage( SPics pic );
      QShortcut *shortcut0;
	    QShortcut *shortcut1;
	    QShortcut *shortcut2;
      QSettings setter;
  int Onselectrow;
  /////////////void resizeEvent ( QResizeEvent * e );
  void contextMenuEvent ( QContextMenuEvent * e );
  QPixmap AppendImageGeneral();
  QModelIndex attuale;
private:
   QString ACTIVENAME;
signals:
   void Redraw();
public slots:
   void Activate( const QModelIndex &index );
   void RemFile();
   void ReplacePic();
   void AppendPics();
   void PasteImage();
   void EsportaPic();
   void NewDesc();
   void ExportFile();
   void ImportFile();
   void in_image( int id );

};






class Foto_DD : public QWidget
{
    Q_OBJECT
//
public:
Foto_DD( QWidget* = 0 )
{
   rotatari = 0;
   //////setAcceptDrops ( true );
}
void paint( QPixmap e )
{
    base = e;
   
    //////////qDebug() << "####### wrapper  " << e.isNull(); 
   
    repaint();
}
void paintEvent(QPaintEvent *e)
{
    QPainter painter;
    painter.begin(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.drawPixmap(0,0,base);
    painter.end();
}
protected:
    void mousePressEvent(QMouseEvent *e) 
{
    emit PrMouse(e);
}
void mouseMoveEvent(QMouseEvent *e)
{
    emit MoMouse(e);
}
private:
    QPixmap base;
    int rotatari;
signals:
     void PrMouse(QMouseEvent *e);
     void MoMouse(QMouseEvent *e);
public slots:
    
void setRotate( int i  )
{
  rotatari = i; 
  repaint();
}

};

class Opscroll : public QScrollArea
{
     Q_OBJECT
//
public:
   Opscroll( QWidget * parent = 0 )
   : QScrollArea(parent)
{
   
}
void wheelEvent(QWheelEvent *event)
{
    int numDegrees = event->delta() / 8;
    int numTicks = numDegrees / 15;
    emit Tick(numTicks);
    return;
}

void keyPressEvent(QKeyEvent *e)
{
    if (e->key() == Qt::Key_Plus)
    {    
    emit Tick(1);
    return;
    }
    
    if (e->key() == Qt::Key_Minus)
    {    
    emit Tick(-1); 
    return;
    }
    QScrollArea::keyPressEvent(e);
}


  signals:
    void Tick(int);
};



class ImageList : public QWidget
{
     Q_OBJECT
//
public:
   ImageList( QWidget * parent = 0 );
   inline void OpenStream( const QString inside ) {
       lista->importStream(inside);
   }
   inline QString GetStream() {
       return lista->streamSave();
   }
    QGridLayout *gridLayout;
    QGroupBox *groupBox;
    QGridLayout *gridLayout1;
    QVBoxLayout *vboxLayout;
    QLabel *label;
    ImageScroller *lista;
    QVBoxLayout *vboxLayout1;
    QLabel *label_2;
    Opscroll *scrolla;  
    Foto_DD *wrapper;
    void SetZoom( int percentual );
    qreal ratio;
protected:
   void wheelEvent(QWheelEvent *event);
   QPixmap Original;
private:
signals:
public slots:
    void FillImage();
    void Wheelgo(int numTicks );
    
};














//
#endif // IMAGESCROLLER_H

